const express=require('express')
const router=express.Router();
const db=require('../utils/db')

// 渲染
router.post('/getData',(req,res)=>{
    const {search,page,count}=req.body;
    const sql=`select * from school_account where name like '%${search}%' limit ${(page-1)*count},${count}`;
    db.query(sql,(err,data)=>{
        if (err) throw err;
        res.send({data:data,code:200,total:data.length})
    })
})
// 删除
router.delete('/delete',(req,res)=>{
    const {ids}=req.body;
    const sql=`delete * from school_account where id in (${ids})`;
    db.query(sql,(err,data)=>{
        if (err) throw err;
        res.send({code:200,msg:'成功'})
    })
})

// 添加
router.post('/add',(req,res)=>{
    const {name,accountType,accountName,accountId, bank,tel,status}=req.body;
    const sql=`insert into school_account values (null,'${name}','${accountType}','${accountName}',${accountId},'${bank}',${tel},'${status}')`;
    db.query(sql,(err,data)=>{
        if (err) throw err;
        res.send({code:200,msg:'成功'})
    })
});

// 修改
router.post('/update',(req,res)=>{
    const {name,accountType,accountName,accountId, bank,tel,status}=req.body;
    const sql=`update school_account set name=${name},accountType=${accountType},accountName=${accountName},accountId=${accountId},bank=${bank},tel=${tel},status=${status} where id=${id};`
    db.query(sql,(err,data)=>{
        if (err) throw err;
        res.send({code:200,msg:'成功'})
    })
})

module.exports=router;